﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CodeCamp12.DAL;
using CodeCamp12.Domain;
using log4net;

namespace CodeCamp12.BLL
{
  public class EventsBL
    {
      private ILog log = LogManager.GetLogger("CodeCamp12.BLL"); 

      /// <summary>
      /// Returns event with id passed in parametar
      /// </summary>
      /// <param name="id"></param>
      /// <returns></returns>
      public Event GetEventById(Guid id)
      {
          var eventDataProvider = new EventDataManagament();
          try
          {
              return eventDataProvider.GetEventById(id);
          }
          catch (Exception ex)
          {
              log.Error(ex);
              throw;
          }
      }

      /// <summary>
      /// Returns the current event
      /// </summary>
      /// <returns></returns>
      public Event GetCurrentEvent()
      {
          var eventDataProvider = new EventDataManagament();
          try
          {
              return eventDataProvider.GetCurrentEvent();
          }
          catch (Exception ex)
          {
              log.Error(ex);
              throw;
          }
      }

      /// <summary>
      /// Returns the location for the current event
      /// </summary>
      /// <returns></returns>
      public Event GetLocationForCurrentEvent()
      {
          var eventDataProvider = new EventDataManagament();
          try 
          {
              return eventDataProvider.GetLocationForCurrentEvent();
          }
          catch (Exception ex)
          {
              log.Error(ex);
              throw;
          }

       
      }

      /// <summary>
      /// Returns all events for the web site
      /// </summary>
      /// <returns></returns>
      public List<Event> GetAllEvents()
      {
          try
          {
              var eventDataProvider = new EventDataManagament();
              return eventDataProvider.GetAllEvents();
          }
          catch(Exception ex)
          {
              
              log.Error(ex);
              throw;
          }

          
      }

      /// <summary>
      /// Updates existing event from the database
      /// </summary>
      /// <param name="eventNew"></param>
      public void UpdateEvent(Event eventNew)
      {
          var eventDataManagament = new EventDataManagament();
          try
          {
              eventDataManagament.UpdateEvent(eventNew);
          }
          catch (Exception ex)
          {
              log.Error(ex);
              throw;
          }
      }

      /// <summary>
      /// Deletes event
      /// </summary>
      /// <param name="eventNew"></param>
      public void DeleteEvent(Event eventNew)
      {
         
          var eventDataProvider = new EventDataManagament();
          
          try
          {
              eventDataProvider.DeleteEvent(eventNew);
              
          }
          catch(Exception ex)
          {
              log.Error(ex);
              throw;
          }
      }

      /// <summary>
      /// Inserts new event for the web site
      /// </summary>
      /// <param name="eventNew"></param>
      public string InsertEvent(Event eventNew)
      {
            var eventId="";
            try
            {
               var eventDataProvider = new EventDataManagament();
               eventId = eventDataProvider.InsertEvent(eventNew);
            }
            catch(Exception ex)
            {
                log.Error(ex);
                throw;
            }
          return eventId;

      }

      /// <summary>
      /// Inserts session in track in time slot for event
      /// </summary>
      /// <param name="sessionId"></param>
      /// <param name="timeSlotId"></param>
      /// <param name="trackId"></param>
      public void InsertSessionInTimeSlotInTrack(Guid sessionId, Guid timeSlotId, Guid trackId)
      {
          var eventDataProvider = new EventDataManagament();
          try
          {
              eventDataProvider.InsertSessionInTimeSlotInTrack(sessionId, timeSlotId, trackId);
          }
          catch (Exception ex)
          {
              log.Error(ex);
              throw;
          }
      }

      /// <summary>
      /// Sets the event with id passed in parametars as current
      /// </summary>
      /// <param name="eventId"></param>
      public void SetEventToCurrent(Guid eventId)
      {
          var eventDataProvider = new EventDataManagament();
          try
          {
              eventDataProvider.SetEventToCurrent(eventId);
          }
          catch (Exception ex)
          {
              log.Error(ex);
              throw;
          }
      }

      /// <summary>
      /// Sets the event with the id passed in parametars as finished
      /// </summary>
      /// <param name="eventId"></param>
      public void SetEventToFinished(Guid eventId)
      {
          var eventDataProvider = new EventDataManagament();
          try
          {
              eventDataProvider.SetEventToFinished(eventId);
          }
          catch (Exception ex)
          {
              log.Error(ex);
              throw;
          }
      }
    }
}
